package com.victor.modular.system.service.impl;

import com.victor.common.constant.cache.Cache;
import com.victor.common.persistence.dao.WeddingDressMapper;
import com.victor.common.persistence.model.WeddingDress;
import com.victor.core.cache.CacheKit;
import com.victor.core.shiro.ShiroKit;
import com.victor.modular.system.dao.AudienceDao;
import com.victor.modular.system.service.BaseService;
import com.victor.modular.system.service.IWeddingDressService;
import com.victor.modular.system.transfer.WeddingDressDto;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class WeddingDressServiceImpl extends BaseService implements IWeddingDressService {
    @Autowired
    private WeddingDressMapper weddingDressMapper;
    @Override
    public void updateWeddingDress(WeddingDressDto WeddingDressDto) throws Exception {
        WeddingDress weddingDress = new WeddingDress();
        weddingDress.setUpdateTime(new Date());
        weddingDress.setUpdateUser(ShiroKit.getUser().getId());
        BeanUtils.copyProperties(WeddingDressDto,weddingDress);
        weddingDressMapper.updateById(weddingDress);
        clearAllCache();
    }

    @Override
    public void addWeddingDress(WeddingDressDto WeddingDressDto) throws Exception {
        WeddingDress weddingDress = new WeddingDress();
        weddingDress.setCreateTime(new Date());
        weddingDress.setCreateUser(ShiroKit.getUser().getId());
        BeanUtils.copyProperties(WeddingDressDto,weddingDress);
        weddingDressMapper.insert(weddingDress);
        clearAllCache();
    }

    @Override
    public void deleteWeddingDress(Integer id) throws Exception{
        WeddingDress weddingDress = weddingDressMapper.selectById(id);
        weddingDressMapper.deleteById(weddingDress);
        CacheKit.removeAll(Cache.CONSTANT);
        clearAllCache();
    }


}
